package fr.web325.utils;


import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.UUID;

public class CodeUtils {
    public String getActiveCode(String username) {
        String dataStr = username + System.currentTimeMillis();
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(dataStr.getBytes(StandardCharsets.UTF_8));
            byte[] s = m.digest();
            StringBuilder result = new StringBuilder();
            for (byte b : s) {
                result.append(Integer.toHexString((0x000000FF & b) | 0xFFFFFF00).substring(6));
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public  String getId(){
        // 返回ID随机字符串  3a0196b2-71c1-4d4d-a4e8-d1f875096f00
        return UUID.randomUUID().toString();
    }
}
